package com.tangcan.blog.Controller;

import com.alibaba.fastjson.JSONObject;
import com.tangcan.blog.Service.ImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.stream.Stream;

@Controller
@EnableAutoConfiguration
@RequestMapping("/Api/img")
@CrossOrigin(origins = "*",maxAge = 3600 ,allowCredentials="true")
public class ImgController {
    @Autowired
    ImgService imgService;

    @RequestMapping(value = "/getImg/{id}", method = RequestMethod.GET)
//    @ResponseBody

    public void getImgById( @PathVariable String id ,HttpServletResponse response )
    {

        imgService.GetImgById(id,response);


    }


    @RequestMapping(value = "/UploadImg", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject UploadImg(@RequestBody String data)
    {
        return imgService.InsetImg(data);
    }


}
